﻿package  plugins.mstandio.AS3Interface.layouts{
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.ContextMenuEvent;
	import flash.events.MouseEvent;
	
	import plugins.mstandio.utils.combobox.ComboBox;		
	import plugins.mstandio.utils.combobox.ComboBoxStyle;		
	import plugins.mstandio.AS3Interface.AS3Interface;
	import plugins.mstandio.AS3Interface.buttons.InterfaceButton;
	import plugins.mstandio.AS3Interface.images.ImageEmbeder;
	
	/**
	 * This is default layout of user interface 
	 * @author mstandio
	 */
	public class Layout_default extends Layout {		
				
		//some basic variables
		private var spacingBetweenButtons:Number = -2;
		private var spacingAllButtonsFromRight:Number = 10;
		private var marginBottomOfNavigationBar:Number = 10;
		private var marginButtonsInsideNavigationBar:Number = 0;	
		private var elementsAplha:Number = 0.8;
				
		// custom elements
		private var navigationBar:Sprite;		
		private var buttonBar:Sprite;					
		private var comboBoxStyle:ComboBoxStyle;
			
		public function Layout_default(layoutObject:Object){  
			super(layoutObject);		          			
			
			this.setAllBitmaps();				  
			this.buildLayout();			
		}				
		
		private function setAllBitmaps():void{ 
			this.button_up.setBitmaps(ImageEmbeder.Bitmap_set1_up_plain, ImageEmbeder.Bitmap_set1_up_over, ImageEmbeder.Bitmap_set1_up_press);						
			this.button_down.setBitmaps(ImageEmbeder.Bitmap_set1_down_plain, ImageEmbeder.Bitmap_set1_down_over, ImageEmbeder.Bitmap_set1_down_press);			
			this.button_left.setBitmaps(ImageEmbeder.Bitmap_set1_left_plain, ImageEmbeder.Bitmap_set1_left_over, ImageEmbeder.Bitmap_set1_left_press);			
			this.button_right.setBitmaps(ImageEmbeder.Bitmap_set1_right_plain, ImageEmbeder.Bitmap_set1_right_over, ImageEmbeder.Bitmap_set1_right_press);			
			this.button_zoomin.setBitmaps(ImageEmbeder.Bitmap_set1_zoomin_plain, ImageEmbeder.Bitmap_set1_zoomin_over, ImageEmbeder.Bitmap_set1_zoomin_press);			
			this.button_zoomout.setBitmaps(ImageEmbeder.Bitmap_set1_zoomout_plain, ImageEmbeder.Bitmap_set1_zoomout_over, ImageEmbeder.Bitmap_set1_zoomout_press);			
			this.button_autorotate.setBitmaps(ImageEmbeder.Bitmap_set1_autorotate_plain, ImageEmbeder.Bitmap_set1_autorotate_over, ImageEmbeder.Bitmap_set1_autorotate_press);				
			this.button_fullscreen.setBitmaps(ImageEmbeder.Bitmap_set1_fullscreen_plain, ImageEmbeder.Bitmap_set1_fullscreen_over, ImageEmbeder.Bitmap_set1_fullscreen_press);				
			this.button_universalmap.setBitmaps(ImageEmbeder.Bitmap_set1_universalmap_plain, ImageEmbeder.Bitmap_set1_universalmap_over, ImageEmbeder.Bitmap_set1_universalmap_press);	
		}
		
		private function buildLayout():void {
			
			//navigation bar (lowest element) 
			this.navigationBar = new Sprite();						
			this.addChild(this.navigationBar);						

			// add branding bar
			this.addChild(this.brandBar);			
			
			// build comboBox
			if (Boolean(this.layoutObject[AS3Interface.PARAM_COMBOBOX_VISIBLE])) {												
				this.addChild(this.comboBox);	// combobox needs to be added at this level					
				
				this.comboBoxStyle = new ComboBoxStyle();				
				 		
				this.comboBoxStyle.fontFamily = "Verdana" // default "Arial" some other system font like Verdana, Courier, Times
				this.comboBoxStyle.fontSize = 19; // default 14
				this.comboBoxStyle.fontColor = 0x858585; // default 0x000000 (black) 				
				//this.comboBoxStyle.fontBold  // default false
				//this.comboBoxStyle.fontItalic // default false
				
				this.comboBoxStyle.marginLeft = 5 // default 3
				this.comboBoxStyle.marginRight = 10; // default 5
										
				//this.comboBoxStyle.elementWidth // default -1 (auto)
				this.comboBoxStyle.elementHeight = 31; // default -1 (auto)				
				//this.comboBoxStyle.elementBackgroundColor //default 0xffffff (white)
				this.comboBoxStyle.elementSelectedColor = 0xdfdfdf; // default 0xefefef (light gray)
				this.comboBoxStyle.elementBorder = false; // default true
				//this.comboBoxStyle.elementBorderColor //default 0xafafaf (dark gray)
				this.comboBoxStyle.elementAlpha = 1; // default 1
				//this.comboBoxStyle.elementSpacing  // default 0
		
				this.comboBoxStyle.buttonBackgroundColor = 0xcfcfcf; // default 0xdfdfdf  (medium gray)
				this.comboBoxStyle.buttonTriangleColor = 0x000000;  // default 0xafafaf (dark gray)
				
				this.comboBoxStyle.mainElementFontColor = 0x000000; // default fontColor
				this.comboBoxStyle.mainElementAlpha = 0.4; // default 1
				this.comboBoxStyle.mainElementBorder = false; // true
				
				this.comboBoxStyle.opensUp = true; // default false
				//this.comboBoxStyle.openingSpeed  // default 0.3
				this.comboBoxStyle.initiallyBlank = true; // default false		
				 
				this.layoutObject[AS3Interface.COMBOBOX].setStyle(this.comboBoxStyle);			
			}	
			
			// building buttonBar
			this.buttonBar = new Sprite();			
			this.buttonBar.alpha = 0.7;
			this.addChild(this.buttonBar);			
			this.buttonBar.addChild(this.button_up);			
			this.buttonBar.addChild(this.button_down);
			this.buttonBar.addChild(this.button_left);
			this.buttonBar.addChild(this.button_right);			
			this.buttonBar.addChild(this.button_zoomin);
			this.buttonBar.addChild(this.button_zoomout);
			this.buttonBar.addChild(this.button_autorotate);
			this.buttonBar.addChild(this.button_fullscreen);			
			if (this.layoutObject[AS3Interface.PARAM_USE_UNIVERSALMAP]) {
				this.buttonBar.addChild(this.button_universalmap);
			}			
			
			// placing buttons inside buttonbar				
			this.button_left.x = 0;
			this.button_right.x = this.button_left.x + this.button_left.width + this.spacingBetweenButtons;
			this.button_up.x = this.button_right.x + this.button_right.width + this.spacingBetweenButtons; 
			this.button_down.x = this.button_up.x + this.button_up.width + this.spacingBetweenButtons;
			this.button_zoomin.x = this.button_down.x + this.button_down.width + this.spacingBetweenButtons;
			this.button_zoomout.x = this.button_zoomin.x + this.button_zoomin.width + this.spacingBetweenButtons;
			this.button_autorotate.x = this.button_zoomout.x + this.button_zoomout.width + this.spacingBetweenButtons;
			this.button_fullscreen.x = this.button_autorotate.x + this.button_autorotate.width + this.spacingBetweenButtons;						
			if (this.layoutObject[AS3Interface.PARAM_USE_UNIVERSALMAP]){
				this.button_universalmap.x = this.button_fullscreen.x + this.button_fullscreen.width + this.spacingBetweenButtons;
			}			
		}				
		
		public override function handleStageResize():void {			
			this.navigationBar.graphics.clear();																	
						
			// drawing background bar
			this.navigationBar.graphics.beginFill(0xffffff,this.elementsAplha);
			this.navigationBar.graphics.drawRect(0, this.stage.stageHeight - this.buttonBar.height - this.marginBottomOfNavigationBar, 
			                                     this.stage.stageWidth, this.buttonBar.height + 2*this.marginButtonsInsideNavigationBar); 			
			this.navigationBar.graphics.endFill();			
			
			// placing buttonBar
			this.buttonBar.x = this.stage.stageWidth - this.buttonBar.width - this.spacingAllButtonsFromRight;
			this.buttonBar.y = this.stage.stageHeight - this.buttonBar.height - this.marginBottomOfNavigationBar + this.marginButtonsInsideNavigationBar;			
			
			// placing comboBox						
			if (this.layoutObject[AS3Interface.PARAM_COMBOBOX_VISIBLE]) {
				this.comboBox.x = this.buttonBar.x - this.comboBox.width - 10;
				//this.comboBox.y = this.buttonBar.y + this.buttonBar.height * 0.5 - this.comboBox.getHeight() * 0.5; // center
				this.comboBox.y = this.buttonBar.y ;
			}						
			
			//placing brandBar
			this.brandBar.x = 2;
			this.brandBar.y = this.stage.stageHeight - this.marginBottomOfNavigationBar - this.brandBar.height;												
		}		
	}	
}